﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using CrystalDecisions.Shared;
using QuanLyQuanCafe.BusinessLogic;
using QuanLyQuanCafe.BusinessObject;
using System.Globalization;


namespace QuanLyQuanCafe
{
    public partial class FrmTraCuuDoanhThuThang : Form
    {
        HoaDonBL hoadonBL = new HoaDonBL();
        public FrmTraCuuDoanhThuThang()
        {
            InitializeComponent();
        }

        private void FrmTraCuuDoanhThuThang_Load(object sender, EventArgs e)
        {
            for (int i = 1; i <= 12; i++)
            {
                cboThang.Items.Add(i);
            }
            cboThang.Text = DateTime.Now.Month.ToString();

            txtNam.Text = DateTime.Now.Year.ToString();

            dateTimePickerNgayBaoCao.Value = DateTime.Now;
            btnInBaoCao.Enabled = false;
        }

        private void btnBaoCaoThang_Click(object sender, EventArgs e)
        {
            string thang = cboThang.Text;
            string nam = txtNam.Text;
            float doanhthu = 0;

            DataTable datatable = hoadonBL.LayKetQuaDanhSachBaoCaoThang(thang, nam);
            for (int i = 0; i < datatable.Rows.Count; i++)
            {
                doanhthu = doanhthu + float.Parse(datatable.Rows[i]["TongTien"].ToString());
            }
            labDoanhThu.Text = doanhthu + " Đ";

            dataGridView1.DataSource = datatable;
            for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
            {
                dataGridView1.Rows[i].Cells["colSTT"].Value = i + 1;
            }
            btnInBaoCao.Enabled = true;
        }

        private void btnInBaoCao_Click(object sender, EventArgs e)
        {
            string thang = cboThang.Text;
            string nam = txtNam.Text;
            
            InBaoCaoThang inbaocaothang = new InBaoCaoThang();
            ParameterValues a = new ParameterValues();
            ParameterDiscreteValue b = new ParameterDiscreteValue();

            DataTable datatable = hoadonBL.LayKetQuaDanhSachBaoCaoThang(thang, nam);
            

            
            inbaocaothang.SetDataSource(datatable);

            b.Value = cboThang.Text ;
            a.Add(b);
            inbaocaothang.DataDefinition.ParameterFields["Thang"].ApplyCurrentValues(a);


            b.Value = txtNam.Text;
            a.Add(b);
            inbaocaothang.DataDefinition.ParameterFields["Nam"].ApplyCurrentValues(a);


            b.Value = DateTime.Now;
            a.Add(b);
            inbaocaothang.DataDefinition.ParameterFields["NgayLapBaoCao"].ApplyCurrentValues(a);


            b.Value = labDoanhThu.Text;
            a.Add(b);
            inbaocaothang.DataDefinition.ParameterFields["DoanhThu"].ApplyCurrentValues(a);

            FrmInBaoCaoThang frminbaocaothang = new FrmInBaoCaoThang(inbaocaothang);
            frminbaocaothang.ShowDialog();
            frminbaocaothang.Dispose();

            btnInBaoCao.Enabled = false;
        }
    }
}
